From 8d072a4f58c8a065cb0c7b3f9f7e190df79fecfb Mon Sep 17 00:00:00 2001 From: Mark Crichton Date: Thu, 1 Jul 1999 06:59:07 +0000 Subject: [PATCH] Now we have very rudimentary tiff support. Now we have very rudimentary tiff support. I should use the loading logic in the GIMP plugin... --- gdk-pixbuf/Makefile.am | 8 +++- gdk-pixbuf/io-tiff.c | 101 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 gdk-pixbuf/io-tiff.c diff --git a/gdk-pixbuf/Makefile.am b/gdk-pixbuf/Makefile.am index 7c058f546d..a1ff62566a 100644 --- a/gdk-pixbuf/Makefile.am +++ b/gdk-pixbuf/Makefile.am @@ -4,7 +4,8 @@ lib_LTLIBRARIES = \ libpixbuf-png.la \ libpixbuf-jpeg.la \ libpixbuf-gif.la \ - libpixbuf-xpm.la + libpixbuf-xpm.la \ + libpixbuf-tiff.la # # The GdkPixBuf library @@ -42,3 +43,8 @@ libpixbuf_xpm_la_SOURCES = \ libpixbuf_gif_la_SOURCES = \ io-gif.c +# +# The TIFF loader +# +libpixbuf_gif_la_SOURCES= \ + io-tiff.c diff --git a/gdk-pixbuf/io-tiff.c b/gdk-pixbuf/io-tiff.c new file mode 100644 index 0000000000..771a052674 --- /dev/null +++ b/gdk-pixbuf/io-tiff.c @@ -0,0 +1,101 @@ +/* + * io-tiff.c: GdkPixBuf I/O for TIFF files. + * Copyright (C) 1999 Mark Crichton + * Author: Mark Crichton + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA. + * + */ + +/* Following code (almost) blatantly ripped from Imlib */ + +#include +#include +#include +#include +#include + +#include "gdk-pixbuf.h" +/*#include "gdk-pixbuf-io.h" */ + +GdkPixBuf *image_load(FILE * f) +{ + GdkPixBuf *pixbuf; + TIFF *tiff; + art_u8 *pixels, *tmppix; + gint w, h, x, y, num_pixs, fd; + uint32 *rast, *tmp_rast; + + g_return_val_if_fail(f != NULL, NULL); + + fd = fileno(f); + tiff = TIFFFdOpen(fd, "libpixbuf-tiff", "r"); + + if (!tiff) + return NULL; + + TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w); + TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h); + num_pixs = w * h; + + /* Yes, it needs to be _TIFFMalloc... */ + rast = (uint32 *) _TIFFmalloc(num_pixs * sizeof(uint32)); + + if (!rast) { + TIFFClose(tiff); + return NULL; + } + + if (TIFFReadRGBAImage(tiff, w, h, rast, 0)) { + pixels = art_alloc(num_pixs * 4); + if (!pixels) { + _TIFFfree(rast); + TIFFClose(tiff); + return NULL; + } + tmppix = pixels; + + for (y = 0; y < h; y++) { + /* Unexplainable...are tiffs backwards? */ + /* Also looking at the GIMP plugin, this + * whole reading thing can be a bit more + * robust. + */ + tmp_rast = rast + ((h - y - 1) * w); + for (x = 0; x < w; x++) { + tmppix[0] = TIFFGetR(*tmp_rast); + tmppix[1] = TIFFGetG(*tmp_rast); + tmppix[2] = TIFFGetB(*tmp_rast); + tmppix[3] = TIFFGetA(*tmp_rast); + tmp_rast++; + tmppix += 4; + } + } + } + _TIFFfree(rast); + TIFFClose(tiff); + + /* Return the GdkPixBuf */ + pixbuf = g_new(GdkPixBuf, 1); + pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4)); + + /* Ok, I'm anal...shoot me */ + if (!(pixbuf->art_pixbuf)) + return NULL; + pixbuf->ref_count = 0; + pixbuf->unref_func = NULL; + + return pixbuf; +} -- 2.30.2